package gui;

import java.util.ArrayList;
import java.util.List;

import com.toedter.calendar.JDateChooserCellEditor;

import core.Profile;
import core.Transaction;
import core.TransactionDirection;
import data.IFilter;

public class Gui
{
	private MainWindow mainWindow;
	private Profile currentProfile;
	
	public Gui(Profile p){
		mainWindow = new MainWindow(this);
		setProfile(p);
	}

	private void setProfile(Profile p){
		currentProfile = p;
		mainWindow.setTitle(p.getName());
		mainWindow.getIncomeList().loadTransactions(p.getData().getTransactions(INCOME_FILTER));
		mainWindow.getExpenseList().loadTransactions(p.getData().getTransactions(EXPENSE_FILTER));
	}
	
	public Profile getProfile(){
		return currentProfile;
	}
	
	public void show(){
		mainWindow.setVisible(true);
	}
	
	public MainWindow getMainWindow(){
		return mainWindow;
	}
	
	private static final IFilter<Transaction> INCOME_FILTER = new IncomeFilter();
	private static class IncomeFilter implements IFilter<Transaction>
	{
		@Override public boolean conforms(Transaction e){
			return e.getDirection() == TransactionDirection.INCOME;
		}
	}

	private static final IFilter<Transaction> EXPENSE_FILTER = new ExpenseFilter();
	private static class ExpenseFilter implements IFilter<Transaction>
	{
		@Override public boolean conforms(Transaction e){
			return e.getDirection() == TransactionDirection.EXPENSE;
		}
	}
	
}
